<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="m" uri="/WEB-INF/mil.tld"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8" />
<title>Blank Page - Ace Admin</title>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- basic styles -->
<link href="/statics/YHZ/css/bootstrap.min.css" rel="stylesheet" />
<link href="/statics/YHZ/css/bootstrap-responsive.min.css"
	rel="stylesheet" />
<link rel="stylesheet" href="/statics/YHZ/css/font-awesome.min.css" />
<!--[if IE 7]>
		  <link rel="stylesheet" href="/statics/YHZ/css/font-awesome-ie7.min.css" />
		<![endif]-->
<!-- page specific plugin styles -->
<!-- ace styles -->
<link rel="stylesheet" href="/statics/YHZ/css/ace.min.css" />
<link rel="stylesheet" href="/statics/YHZ/css/ace-responsive.min.css" />
<link rel="stylesheet" href="/statics/YHZ/css/ace-skins.min.css" />
<!--[if lt IE 9]>
		  <link rel="stylesheet" href="/statics/YHZ/css/ace-ie.min.css" />
		<![endif]-->
</head>
<body>
	<!--/.navbar-->
	<jsp:include page="include/navbar.jsp" />
	<!--/.container-fluid-->
	<div class="container-fluid" id="main-container">
		<!-- menu toggler -->
		<jsp:include page="include/menu.jsp" />
		<!--/#sidebar-->
		<div id="main-content" class="clearfix">
			<div id="breadcrumbs">
				<ul class="breadcrumb">
					<li><i class="icon-home"></i> <a href="index.do">主页</a><span
						class="divider"><i class="icon-angle-right"></i></span></li>
					<li class="active">促销商品管理</li>
				</ul>
				<!--.breadcrumb-->
			</div>
			<!--#breadcrumbs-->
			<div id="page-content" class="clearfix">
				<div class="row-fluid">
					<!-- PAGE CONTENT BEGINS HERE -->
					<h3 class="header smaller lighter blue">促销商品管理</h3>
					<div class="row-fluid">
						<ul class="nav nav-tabs" id="myTab">
  							<li class="active"><a href="#">已参加商品</a></li>
  							<li>               <a href="#">出售中商品</a></li>
						</ul>
						</BR>
						<div class="tab-pane" id="tabProds">
							<div style="display:none">
								<form action="">
								  	商品名称：<input id="prodName" type="text"/>
								  	商品编码：<input id="prodCode" type="text"/>
									<input type ="button" value="搜索" onclick="javascript:getProdList(1,10);"/>
									<input type ="button" value="清空"/>
									<input type="hidden" id="prodIds" value="${fn:replace(fullMinus.productInfo,';',',')}" />
									<input type="hidden" id="fc_id" value="${fullMinus.id}" />
								</form>
							</div>
							<table id="tbProds"
								class="table table-striped table-bordered table-hover">
								<thead>
									<tr>
										<th class="center">
											<label><input type="checkbox" /><span class="lbl"></span></label>
										</th>
										<th>商品图片</th>
										<th>商品编码&名称</th>
										<th>商品价格</th>
										<th>商品库存</th>
										<th>操作</th>
									</tr>
								</thead>
								<tbody>
								</tbody>
							</table>
							<div id="pageJQ" class="pagination pagination-centered">
							</div>
						</div>
						<!--/span-->
					<!--/row-->
					<!-- PAGE CONTENT ENDS HERE -->
				</div>
				<!--/row-->
			</div>
			<!--/#page-content-->
		</div>
		<!-- #main-content -->
	</div>
	<!--/.fluid-container#main-container-->
	<!-- basic scripts -->
	<script src="/statics/YHZ/1.9.1/jquery.min.js"></script>
	<script src="/statics/YHZ/js/bootstrap.min.js"></script>
	<!-- page specific plugin scripts -->
	<!-- ace scripts -->
	<script src="/statics/YHZ/js/ace-elements.min.js"></script>
	<script src="/statics/YHZ/js/ace.min.js"></script>
	<script src="/statics/pagination.js"></script>
	<!-- inline scripts related to this page -->
	<script type="text/javascript">
	var firstActive = true;
	var prodIds = $("#prodIds").val();
	$(function() {
		$('#myTab a').click(function (e) {
			e.preventDefault();
			$(this).tab('show');
			
			
			firstActive = $('#myTab li:first').hasClass("active");
			if(firstActive){
				$("#tabProds div:first").hide();
				$("#prodIds").val(prodIds);
			}
			else{
				$("#tabProds div:first").show();
				$("#prodIds").val("");
			}
			alert($("#prodIds").val());
			if(!firstActive || prodIds!='')
				getProdList(1,10);
			$("#tbProds tbody tr").remove();
			$("#pageJQ").html("");
		})
		
		if(!firstActive || prodIds!='')
			getProdList(1,10);
	})
	
	//查询分类（商品分类&店铺分类）
	function getCateList() {
		var href = "/yhz/getCateList.do";
		$.getJSON(href, {"type":0}, function (data){
			if(data.ret == 0){
				$("#cateP").empty();
				$("#cateP").append("<option value='-1'>全部</option>");
				for (index in data.data){
					elemObj = data.data[index];
					$("#cateP").append("<option value='"+elemObj.categoryId+"'>"+elemObj.categoryName+"</option>");
				}
			}
		});
		
		var href = "/yhz/getCateList.do";
		$.getJSON(href, {"type":1}, function (data){
			if(data.ret == 0){
				$("#cateM").empty();
				$("#cateM").append("<option value='-1'>全部</option>");
				for (index in data.data){
					elemObj = data.data[index];
					$("#cateM").append("<option value='"+elemObj.categoryId+"'>"+elemObj.categoryName+"</option>");
				}
			}
		});
	}
	
	//查询商品列表
	function getProdList(pageNo, pageSize) {
		var href = "/yhz/getProdList.do";
		$.getJSON(href, {"prodIds":$("#prodIds").val(),
			"prodName":$("#prodName").val(),
			"prodCode":$("#prodCode").val(),
			"pageNo":pageNo,
            "pageSize":pageSize}, function (data) {
			if(data.ret == 0){
				var _html;
				$("#tbProds tbody tr").remove();
				for (index in data.data.list){
					elemObj = data.data.list[index];
					
					var prodImg = '';
					if(elemObj.prodImg != null){
						prodImgArr = elemObj.prodImg.split(',');
						for(i in prodImgArr){
							prodImg = prodImgArr[i].split('|')[1];
							if(prodImgArr[i].split('|')[2] == 1) break;
						}
					}
					_html = "<tr>"+
							 	"<td class='center'><label><input type='checkbox' /><span class='lbl'></span></label></td>"+
							 	"<td><img src=\""+prodImg+"\" width=\"50\" height=\"50\"/><\BR>"+elemObj.productCode+"</td>"+
							 	"<td><a href=\""+elemObj.prodDetailUrl+"\" target=\"_blank\">"+elemObj.productCname+"</a></td>"+
							 	"<td>999</td>"+
							 	"<td>"+elemObj.stockStatus+"</td>"+
							 	"<td><a href=\"javascript:fullCutDetailEdit('"+$("#fc_id").val()+"','"+(firstActive?"-":"+")+elemObj.productId+"');\">"+(firstActive?"取消":"参加")+"</a></td>"+
							"</tr>";
					$("#tbProds tbody").append(_html);
				}
				pageTag(data.data.pageNo,data.data.pageSize,data.data.totalRecord,getProdList);
			}
		});
	}
	
	
	function fullCutDetailEdit(id, changeInfos) {
		var href = "/yhz/fullCutDetailEdit.do";
		$.getJSON(href, {"id":id,
			             "changeInfos":changeInfos}, function (data) {
			if(data.ret == 0){
				$(this).html("已改");
			}
			else{
				alert(data.msg);
			}
		});
	}
	</script>
</body>
</html>